﻿@model Sheng.Enterprise.Web.Models.LoginViewModel

@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>登录</title>
    @Styles.Render("~/Content/css")
    @Styles.Render("~/Content/Login.css")
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/common")

    @Scripts.Render("~/Scripts/layer/layer.js")
    @Scripts.Render("~/Scripts/json2.js")

    <script src="~/Scripts/MD5.js" type="text/javascript"></script>

    <script type="text/javascript">

        $(document).ready(function ()
        {
            var account = getCookie("account");
            if(account!= undefined && account!= ""){
                $("#txtAccount").val(account);
                $("#chkRememberAccount").attr("checked","checked");
            }

            $("[keyenter]").keypress(function (e)
            {
                if (e.keyCode === 13)
                {
                    login();
                }
            });
       });

    function showMask()
    {
        $("#divLoginAreaMask").show();
        $("#divLoginAreaMaskContent").show();
    }

    function hideMask()
    {
        $("#divLoginAreaMask").hide();
        $("#divLoginAreaMaskContent").hide();
    }

    function login()
    {        
        //$("#form1").validate().element($("#salary"))

       if ($("#formLogin").validate({
            rules: {
                     "txtAccount": "required",
                     "txtPassword": "required"
        },
            messages: {
                     "txtAccount": "!",
                     "txtPassword": "!"
        }
        }).form() == false)
            return;

        //var password = hex_md5($("#txtPassword").val());
        //alert(password.toUpperCase());

        var args = new Object();
        args.Account = $("#txtAccount").val();
        args.Password = hex_md5($("#txtPassword").val()).toUpperCase();

        showMask();

        $.ajax({
            url: "/Api/UserContext/Login",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(args),
            success: function (data, status, jqXHR)
            {
                if (data.Success)
                {
                    //如果成功，不隐藏mask，否则跳转期间页面还可操作

                    if($("#chkRememberAccount").is(":checked"))
                    {
                        setCookie("account",args.Account);
                    }
                    else{
                        removeCookie("account");
                    }

                    window.location.href = "/WeeklyReport/Post";
                } else
                {
                    hideMask();

                    layerAlert(data.Message,function(){$("#txtPassword").focus();});
                }
            },
            error: function (xmlHttpRequest)
            {
                //layer.closeAll();
                //hideMask();

                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }
    </script>
</head>
<body>
    <div id="divContainer">
        <div id="divLoginAreaBackground">
        </div>
        <div id="divLoginArea">
            <form id="formLogin">
                <table width="270" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td height="40" class="font_black_20">帐户：</td>
                    </tr>
                    <tr>
                        <td height="40"><input value="15997352948" name="txtAccount" type="text" class="input_noborder_20" style="width:240px;" id="txtAccount" keyenter /></td>
                    </tr>
                    <tr>
                        <td height="40" class="font_black_20">密码：</td>
                    </tr>
                    <tr>
                        <td height="40"><input value="123456" name="txtPassword" type="password" class="input_noborder_20" style="width:240px;" id="txtPassword" keyenter /></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td><input  name="btnLogin" type="button" class="btn_blue" id="btnLogin" value="登 录" onclick="login()" />
                        <input name="btnLogin2" type="button" class="btn_orange" id="btnLogin2" value="注 册" style="margin-left:25px;" onclick="goUrl('@Url.Action("Register")')" />
                        </td>
                    </tr>
                    <tr>
                        <td height="10"></td>
                    </tr>
                    <tr>
                        <td><input  id="chkRememberAccount" type="checkbox" class="input_checkbox" /> <label for="chkRememberAccount">记住帐户</label></td>
                    </tr>
                    <tr>
                        <td height="15" ></td>
                    </tr>
                    <tr>
                        <td><span><a href="~/Home/ResetPassword" class="a_blue_15">找回密码</a></span><span style="margin-left:30px;"><a target="_blank" class="a_blue_15" href="/Home/Browser/WeeklyReport">系统说明书</a></span></td>
                    </tr>
                </table>
                </form>
        </div>
        <div id="divLoginAreaMask" style="display:none">

        </div>
        <div id="divLoginAreaMaskContent" style="display:none">
            <span style="margin-left:20px;">请稍候..</span>
        </div>
    </div>
   

</body>
</html>
